<?php
/**
 * Announce Add a new One
 * 
 * 
 */
use Fox\Ressources;
use Hive\Mission\Announce;
use Fox\Popup;
use Fox\Generator;
use Fox\Html\Screen;

$xview = Xview::instance();
/* @var $mission \Hive\Mission */
$mission = Xview::instance()->component('missions', 'object');
$screen = new Screen('sAnnounce','create',null,true,Generator::ajaxReload('contentCol',
			Generator::url('missions','announces',null,array('mid' => $mission->getId()))));

// Header Data
$bHeader = $xview->component('missions','announceHeader');
$screen->add($bHeader);
// Skills
$bSkills = $xview->component('missions','announceSkills');
$screen->add($bSkills);
// Html Content
$bContent = $xview->component('missions','announceDescription');
$screen->add($bContent);

if($screen->submitted())  {
	
	$fields = $screen->get();
	if(!$screen->errors()) {
		try {
			$fields['missionid'] = $mission->getId();
			$announce = new Announce();
			$announce->setFields($fields);
			$announce->create();
			Fox\Message::Success(Msg(Hive::BUNDLE,Hive::ANNOUNCE_HAS_BEEN_CREATED,$fields['reference']));
		} catch(\Fox\Object\Exception\Save $e) {
			var_dump($e);
			Fox\Message::Error($e->getMessage());
		}
	}
	echo $xview->messages();
	exit;
}

$html = $screen->display();
$popup = new Popup('pAnnounce',Msg(Hive::BUNDLE,Hive::ANNOUNCE_NEW),$html,890);
echo $popup->display();
echo Ressources::instance()->dump();